Skip to content

feat(builtin): add ArrayView::strip_prefix and strip_suffix#3430

Merged
bobzhang merged 5 commits intomainfrom
hongbo/ArrayView_strip
Apr 26, 2026
Merged

feat(builtin): add ArrayView::strip_prefix and strip_suffix#3430
bobzhang merged 5 commits intomainfrom
hongbo/ArrayView_strip

Conversation

@bobzhang
Copy link
Copy Markdown
Contributor

@bobzhang bobzhang commented Apr 15, 2026

Summary

  • Add ArrayView::strip_prefix and ArrayView::strip_suffix, returning ArrayView[T]?.
  • Unlike Array's versions (which allocate a new array), the view variants are O(1) sub-views — matching the StringView precedent.

Test plan

  • moon fmt, moon check, moon info
  • moon test -p moonbitlang/core/builtin — 2746/2746 pass
  • Covers: basic match/no-match, empty prefix/suffix, full-length match, prefix/suffix longer than view, sliced-view case, and a backing-array sharing test (mutating source reflects in stripped view).

🤖 Generated with Claude Code


Open with Devin

Copy link
Copy Markdown

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 2 additional findings.

Open in Devin Review

@coveralls
Copy link
Copy Markdown
Collaborator

coveralls commented Apr 15, 2026

Coverage Report for CI Build 3943

Coverage decreased (-0.002%) to 94.888%

Details

  • Coverage decreased (-0.002%) from the base build.
  • Patch coverage: 8 of 8 lines across 2 files are fully covered (100%).
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 15572
Covered Lines: 14776
Line Coverage: 94.89%
Coverage Strength: 220355.35 hits per line

💛 - Coveralls

@bobzhang bobzhang force-pushed the hongbo/ArrayView_strip branch 4 times, most recently from ce369b3 to 59ca09d Compare April 16, 2026 01:47
bobzhang and others added 2 commits April 26, 2026 11:27
Mirror Array::strip_prefix / strip_suffix on ArrayView. The view variants
return ArrayView[T]? (a sub-view) rather than allocating, matching the
StringView precedent.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Mirror the String::strip_suffix / StringView::strip_suffix pattern:
Array::strip_suffix now takes an ArrayView[T] suffix and returns
ArrayView[T]?, delegating to ArrayView::strip_suffix. Avoids the
allocate-and-blit cost when callers only need a view of the prefix.
@bobzhang bobzhang force-pushed the hongbo/ArrayView_strip branch from 59ca09d to 2d75cb6 Compare April 26, 2026 03:30
devin-ai-integration[bot]

This comment was marked as resolved.

bobzhang and others added 3 commits April 26, 2026 13:09
Mirrors the strip_suffix migration so Array::strip_prefix takes
ArrayView[T] and returns ArrayView[T]?, sharing the backing array
instead of allocating. The doctests and tests switch to debug_inspect
because Show for X? is deprecated in favor of Debug.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
`moon info` now emits a separate top-level `fn Type::Type(..)` constructor
for each `fn new(..)` declared inside a struct. These files were stale
relative to the current toolchain, causing moon-info-check to fail.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@bobzhang bobzhang merged commit 8b787dd into main Apr 26, 2026
12 of 19 checks passed
@bobzhang bobzhang deleted the hongbo/ArrayView_strip branch April 26, 2026 05:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants